# Contributor: kpcyrd <git@rxv.cc>
# Maintainer: kpcyrd <git@rxv.cc>
pkgname=acme-redirect
pkgver=0.6.2
pkgrel=4
pkgdesc="Tiny http daemon that answers acme challenges and redirects everything else to https"
url="https://github.com/kpcyrd/acme-redirect"
# ppc64le and s390x and riscv64 blocked by ring crate
arch="all !ppc64le !s390x !riscv64"
license="GPL-3.0-or-later"
makedepends="
	cargo
	cargo-auditable
	openssl-dev>3
	scdoc
	"
subpackages="$pkgname-doc
	$pkgname-openrc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
install="$pkgname.pre-install"
options="net"
source="$pkgname-$pkgver.tar.gz::https://github.com/kpcyrd/acme-redirect/archive/v$pkgver.tar.gz
	getrandom-0.2.10.patch
	"

build() {
	cargo auditable build --release --locked

	mkdir -p completions
	"target/release/acme-redirect" completions bash > completions/acme-redirect.bash
	"target/release/acme-redirect" completions zsh > completions/_acme-redirect
	"target/release/acme-redirect" completions fish > completions/acme-redirect.fish

	make docs
}

check() {
	cargo test --release --locked
}

package() {
	install -Dm755 "$builddir/target/release/acme-redirect" -t "$pkgdir/usr/bin"

	install -Dm755 "$builddir/contrib/openrc/$pkgname.initd" "$pkgdir/etc/init.d/$pkgname"
	install -Dm755 "$builddir/contrib/cron/acme-redirect.cron" \
		"$pkgdir"/etc/periodic/daily/acme-redirect

	install -Dm644 "$builddir/contrib/confs/acme-redirect.conf" -t "$pkgdir/etc"
	install -Dm644 "$builddir/contrib/confs/certs.d/example.com.conf" "$pkgdir/etc/acme-redirect.d/example.com.conf.sample"

	install -Dm644 -t "$pkgdir/usr/share/man/man1" \
		"$builddir/contrib/docs/acme-redirect.1"
	install -Dm644 -t "$pkgdir/usr/share/man/man5" \
		"$builddir/contrib/docs/acme-redirect.conf.5" \
		"$builddir/contrib/docs/acme-redirect.d.5"

	install -Dm644 "$builddir/completions/acme-redirect.bash" \
		"$pkgdir/usr/share/bash-completion/completions/acme-redirect"
	install -Dm644 "$builddir/completions/_acme-redirect" \
	    "$pkgdir/usr/share/zsh/site-functions/_acme-redirect"
	install -Dm644 "$builddir/completions/acme-redirect.fish" \
		"$pkgdir/usr/share/fish/vendor_completions.d/acme-redirect.fish"
}

sha512sums="
2b2a554e6cc568b85ec2198522942cf83128d91f120ac2c2cf0fc8a7d38d1b9d8a10ffdd03d1076e6e7f38d69c75285dd54cea5dbba37418039fe8055dc0e398  acme-redirect-0.6.2.tar.gz
ecb8e9d6791b5e6f72f03db533ccb76020af5d5239092b02bf16fb20e0ca739b24e7ddddcd22b7c48866dd9f0617e73794d246d50f1e81e029905ec31630a034  getrandom-0.2.10.patch
"
